//
//  JZHPothTableViewCell.m
//  极致荟
//
//  Created by hetao on 14-5-7.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHPothTableViewCell.h"
#import "JZHPusMessgeViewController.h"
#import "CJBrowseUIImageView.h"
@implementation JZHPothTableViewCell
 NSMutableArray *array;
- (void)awakeFromNib
{
    [self addSubview:self.anview];
    self.anview.hidden=YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (CGFloat)addCellData:(JZHTheDiary*)td
{
    [self.conten setText:td.content];
    [self.conten sizeToFit];
    [self addimagedata:td.images path:td.pathHead];
    [self setFrame:CGRectMake(0, 0, self.frame.size.width, self.addimageview.frame.origin.y+self.addimageview.frame.size.height)];
    CGFloat hige=self.addimageview.frame.origin.y+self.addimageview.frame.size.height;
    NSLog(@"%f",self.frame.size.height);
   
    return hige+10;
}
- (void)addimagedata:(NSArray *)arr path:(NSString *)path
{
    CGRect rect=self.addimageview.frame;
    if(arr.count==0)
    {
        [self.addimageview setFrame:CGRectMake(rect.origin.x, rect.origin.y, 0, 0)];
        return;
    }
    for(int i=0;i<arr.count;i++)
    {
        CJBrowseUIImageView *image=[[CJBrowseUIImageView alloc]initWithFrame:CGRectMake(i*50+i*10, 0, 50, 50)];
        [ImageCache imageUrl:[path stringByAppendingString:arr[i]] UiImageview:image];
        [self.addimageview addSubview:image];
        [image showImages:[[NSArray alloc]initWithObjects:image.image, nil]];
    }
    
    [self.addimageview setFrame:CGRectMake(rect.origin.x, self.conten.frame.origin.y+self.conten.frame.size.height, 50, 50)];
}


- (IBAction)openCamer:(id)sender {
    UIActionSheet *actionshee=[[UIActionSheet alloc]initWithTitle:@"操作" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"照相" otherButtonTitles:@"相册", nil];
    [actionshee showInView:[UIApplication sharedApplication].keyWindow];
}
#pragma mark actionsheet 代理方法实现-------------
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==1)//找一张
    {
        
        if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
            [[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前相册不可用" delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
            return;
        }
        UIImagePickerController *imagecont=[[UIImagePickerController alloc]init];
        imagecont.delegate=self;
        
        [self.viewcontroller presentViewController:imagecont animated:YES completion:^{}];
        
    }else if (buttonIndex==0)//照一张
    {
        if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            [[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前相机不可用" delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
            
            return;
        }
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
        [imagePickerController setDelegate:self];
        [imagePickerController setAllowsEditing:YES];
        [self.viewcontroller presentViewController:imagePickerController animated:YES completion:^{}];
        
        
    }
    
}

#pragma mark 相册 代理方法实现-------------
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *img;
        NSLog(@"%@",info);
    if(picker.sourceType == UIImagePickerControllerSourceTypeCamera){
        img=[info objectForKey:UIImagePickerControllerEditedImage];
    }else {
        img=[info objectForKey:UIImagePickerControllerOriginalImage];
    }
    [self.viewcontroller dismissViewControllerAnimated:NO completion:^{
    }];
    [self.viewcontroller.navigationController pushViewController:[JZHPusMessgeViewController shareImage:img] animated:YES];
    
    
}

- (IBAction)zan:(id)sender

{
     [self showzan:self.anbut];
}
- (IBAction)showzan:(UIButton *)sender
{
   
    CGRect rect=self.anview.frame;
    
    if(sender.selected)
    {
       
               [UIView animateWithDuration:.3 animations:^{
            [self.anview setFrame:CGRectMake(sender.frame.origin.x+rect.size.width, self.anview.frame.origin.y, rect.size.width, rect.size.height)];
        } completion:^(BOOL finished) {
            self.anview.hidden=YES;
            sender.selected=NO;
        }];

    }else
    {
        
         [self.anview setFrame:CGRectMake(sender.frame.origin.x, sender.frame.origin.y-3, rect.size.width, rect.size.height)];
        self.anview.hidden=NO;
        [UIView animateWithDuration:.3 animations:^{
            [self.anview setFrame:CGRectMake(sender.frame.origin.x-rect.size.width, self.anview.frame.origin.y, rect.size.width, rect.size.height)];
        } completion:^(BOOL finished) {
            sender.selected=YES;
        }];
    }
   
   
}

- (IBAction)ping:(id)sender
{
    [self showzan:self.anbut];
}
@end
